package com.dayuanit.dy8.mall.springbootmall.controller;

import com.dayuanit.dy8.mall.springbootmall.dto.ResponseDTO;
import com.dayuanit.dy8.mall.springbootmall.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
public class CartController extends BaseController {

    @Autowired
    private CartService cartService;

    @RequestMapping("/cart/add")
    public ResponseDTO addCart(int commonId, int buyNum, HttpSession session) {
        int userId = getUserId(session);
        cartService.add(commonId, buyNum, userId);
        return ResponseDTO.success();
    }

    @RequestMapping("/cart/list")
    public ResponseDTO listCart(HttpSession session) {
        return ResponseDTO.success(cartService.listCart(getUserId(session)));
    }
}
